package com.lst.api.vo.response;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @author: Frank
 * @date: 2019/10/11 18:39
 * @version: V1.0
 */
@Data
@NoArgsConstructor
public class PageInfo<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(name = "pageNum", value = "当前页", dataType = "Long")
    private long pageNum = 1L;

    @ApiModelProperty(name = "pageSize", value = "页大小", dataType = "Long")
    private long pageSize = 0L;

    @ApiModelProperty(name = "records", value = "查询数据", dataType = "List")
    private List<T> records = Collections.EMPTY_LIST;

    @ApiModelProperty(name = "pages", value = "总页数", dataType = "Long")
    private long pages = 0L;

    @ApiModelProperty(name = "total", value = "总条数", dataType = "Long")
    private long total = 0L;

    public PageInfo(IPage<T> page) {
        if (page == null) {
            return;
        }
        this.pageNum = page.getCurrent();
        this.pageSize = page.getSize();
        this.records = page.getRecords();
        this.pages = page.getPages();
        this.total = page.getTotal();
    }

    public void copyProperties(IPage page) {
        if (page == null) {
            return;
        }
        this.pageNum = page.getCurrent();
        this.pageSize = page.getSize();
        this.pages = page.getPages();
        this.total = page.getTotal();
    }
}
